Fly3D SDK

Tutorials

Home

Tutorial 9

Creating a new Fly3D plug-in

· Introduction

At the end of this tutorial you will have created a new Fly3D plug-in to be used in your games. The plug-in will implement a single game object named blink_light. The object will be a dynamic light source that constantly changes its radius based on a predefined time interval.

· Visual C++ operations

1) Open the Visual C++ Fly3D Plug-ins Workspace

2) Select the menu option File/New to create a new project

3) Select the projects tab and the Fly3D Plug-in Wizard

4) Set the project location to the flysdk\plugin path and name the project 'tutorial'. Make sure to select 'add to curent workspace' to keep all Fly3D plug-in projects in a single workspace.

5) On the first wizard step, add a single class named 'blink_light'

6) On the second wizard step, add three parameters:

name: 'color'        type: color
name: 'illumradius'  type: float
name: 'blinktime'    type: int

7) On the third wizard step, select the Fly3D SDK path and click Finish.

8) You should now be able to compile the plug-in with no errors.

9) Now we will add the blink light functionality. Open the tutorial.cpp file and add the following code to the blink_light::step function:

int blink_light::step(int dt)
{
  // compute current radius
  float r=illumradius*
          ((flyengine->cur_time%blinktime)/1000.0f);

  // illuminate around
  flyengine->send_bsp_message(
         flyengine->bsp, pos, r, FLYOBJM_ILLUM, 0, &color);

  // return 0 as we have not moved (changed pos)
   return 0;
}

10) If the blink_light is to be destroyed after say 30 seconds of illumination, set its life parameter to 30000 and add the following line anywhare in the blink_light::step function:

// subtract elapsed time from object's life
life-=dt;

When the blink_light's life value truns negative, it will be destroyed by the engine.

11) Use the ALT-F7 key to edit the project settings. On the link tab, change the output file name to '../tutorial.dll'. This will save the compiled dll to the flysdk\plugin directory with all other Fly3D plug-ins (make sure to change this option for the release and debug versions).

12) Compile the tutorial (flysdk\plugin\tutorial.dll should be built) and we are ready to add the plug-in object to the level from previous tutorials.

13) Run the plug-in (debug it) using the F5 key and select the flyEditor.exe to open (or just run a standalone copy of flyEditor if no debug is needed).

· flyEditor operations

1) Open the level .fly file cretated in previous tutorials and add the tutorial.dll to it just like in tutorial 7.

2) Add a new blink_light object and set its parameters as follows:

active    = 1 (activate on startup)
color     = any color you choose for the light, but not black!
radius    = 100 (10 meters)
life      = 30000 (30 sec)
blinktime = 1000 (1 second)

This active parameters tells the engine to activate a copy of the object on scene startup. If we set it to 0, the blink_light will be on the stock and can be used as a parameter in another game object or activated by another game object (and will not be visible until then).

3) Run the level (setting the render and starting simmulation). You should see the blink_light illuminating the faces near its position (0,0,0). You can change its parameters and see the results in real-time in the render view.